**POQ DO FILE
**WRITTEN BY JACK MEWHIRTER
**UPDATED 02/14/2024

//YOU'LL NEED THE FOLLOWING PACKAGES
//NOTE: SOME PACKAGES MAY NOT BE COMPATABLE WITH OLDER VERSIONS OF STATA 
//ssc install vcemway 
//ssc install mplotoffset
//ssc install combomarginsplot
//note scheme=plottig (findit gr0070)


//VARIABLES USES IN PRIMARY ANALYSIS AND CORRESPONDING VARIBALE NAMES (IN PAPER)
//NOTE: SEE MAIN TEXT AND TABLE A1 FOR MEASUREMENT DETAILS
//blame_att_short (Blame Level)
//party_id_alt_long (Partisanship)
//round (Wave)
//race (Race)
//college (College)
//male (Male)
//income (Household Income)
//psindex (PS Index)
//nsindex  (NS Index)
//trust_science_polmotives (TS Political)
//trust_science_betterment (TS Betterment)
//trust_science_community  (TS Community)
//financial_impact_personal (HS Personal-Finance)
//mental_impact_personal  (HS Personal-Mental)
//financial_impact_network (HS Network-Finance)
//mental_impact_network  (HS Network-Mental)
//infected_personal (Infected-Personal)
//infected_network (Infected-Network)
//high_risk (Risk Index)
//age (Age)
//county_density (County Density)
//county_covid_cap_cases (County Cases Cap)
//state_cases_cap (State Cases Cap)
//dem_gov (Dem Governor)
//dem_leg  (Dem Legislature )
//virus_forecast  (Outlook)
//individual_responsibility (Individualism)
//perceived_safety (Perceived Safety)



//VARIABLES USED IN CODE NOT FULLY DESCIBED IN TABLE A1
//no_limitations: defines whether respondent identified there being any limitations to gov response (=1) or not (=0)
//div= census division
//blame_att=blame attribution varaible that disaggregates state and local blame
//united= whether a person lives in a state with united=1 or divided (=0) gov
//test_ways=low quality open response ID (=.) if high quality (1-4 is failed test) see SM Section F
//duration=seconds to completion
//blame_att_short_nons= blame_att_short w/ no and ns added options (=3,4)
//COUNTYNAME  (ID for county-level REs)
//respondent_id (ID for respondent-level REs)


//START
clear
set more off
use "C:\Users\Mewhirjk\OneDrive - University of Cincinnati\Desktop\Working Projects\Blame Attribution\replication_files\POQ_data.dta"
keep test_ways united div blame_att obs no_limitations blame_att_short party_id_alt_long round race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast  individual_responsibility perceived_safety COUNTYNAME  respondent_id duration blame_att_short_nons









//MAIN PAPER
//MAIN MODEL w/ MEs and PPs
vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast  individual_responsibility perceived_safety , cluster(COUNTYNAME  respondent_id)
//outreg2 using main, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
marginsplot, yline(0) level(95) recast(scatter)
margins, at(party=(0(1)6) round=(0 1)) 
mplotoffset,  level(95) recast(scatter)


//TABLE 1: MADE MANUALLY
bysort round: tab no_limitations
bysort round: tab blame_att

//ROUND 1=
	//total=12032
	//yes=8959 
	//yes, fed= 6484 =53.89
	//yes, state=1931 =16.05
	//yes, local=541 =4.50
	//no=1508 =12.53
	//NS=1565 =13.01

//ROUND 2=
	//total=3350 or  (3352, 2 missing in attribute)
	//yes=2048 (count as 2046 for %)
	//yes, fed=1205  =35.97
	//yes, state=752 = 22.45
	//yes, local=89  =2.66
	//no=565 = 16.86
	//NS=739 = 22.05







**APPENDIX**

//PART A
//Summary Stats
bysort round: sum     blame_att_short college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast  individual_responsibility perceived_safety 
bysort round: tab party_id_alt_long  //note: mean=%
bysort round: tab race 

//TABLE A1: NOTE--THIS WAS MADE MANUALLY
//SWITCHERS
gen blame_att_combo=blame_att
replace blame_att_combo=4 if no_limit==1 //=no	
replace blame_att_combo=5 if no_limit==2 //=ns
sort respondent round
gen blame_att_combo_prev=blame_att_combo[_n-1] if round==1 & obs==2


tab blame_att_combo if blame_att_combo_prev==2 & obs==2
//Nat-Nat: 39.93
//Nat-State: 21.36
//Nat-Local: 2.09
//Nat-No: 16.33
//Nat-NS: 20.30

tab blame_att_combo if blame_att_combo_prev==3 & obs==2
//State-State: 33.84
//State-Nat: 35.78
//State-Local: 3.45
//State-No: 12.07
//State-NS: 14.87

tab blame_att_combo if blame_att_combo_prev==1 & obs==2
//Local-Local: 7.96 
//Local-Nat: 38.94
//Local-State: 24.78
//Local-No: 14.16
//Local-NS: 14.16

tab blame_att_combo if blame_att_combo_prev==4 & obs==2
//No-No: 29.74
//No-Nat: 27.63
//No-State: 21.31
//No-Local: 3.51
//No-NS: 17.80

tab blame_att_combo if blame_att_combo_prev==5 & obs==2
//NS-NS: 47.11
//NS-Nat: 24.21
//NS-State: 14.74
//NS-Local: 2.11
//NS-NO: 11.84














//PART B: ATTRITION
//GEN PROP SCORE
//Probability Score Weighting
sort respondent_id round
gen both_round=0
replace both_round=1 if obs==2
logit       both_round i.party_id_alt_long i.race college male income age county_density dem_gov dem_leg high_risk i.div if round==0 
//outreg2 using nra, word dec(2) replace alpha(.01, .05)

//CREATE WEIGHTS
predict propensity 
gen inv_prop=1/propensity if both_round==1
replace inv_prop=1/(1-propensity) if both_round==0
replace inv_prop=inv_prop[_n-1] if round==1
//replace inv_prop=1 if round==0

svyset respondent [pweight=inv_prop]
svy: logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast individual_responsibility perceived_safety
//outreg2 using nra, word dec(2) alpha(.01, .05)
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

//Assessing Balance (make Table B2 manually)
tab party_id_alt_long if round==0
tab party_id_alt_long if round==1
tab race if round==0
tab race if round==1
mean college if round==0
mean college if round==1
mean male if round==0
mean male if round==1
mean income if round==0
mean income if round==1
mean age if round==0
mean age if round==1
mean county_density if round==0
mean county_density if round==1
mean dem_gov if round==0
mean dem_gov if round==1
mean dem_leg if round==0
mean dem_leg if round==1
mean high_risk if round==0
mean high_risk if round==1
tab div if round==0
tab div  if round==1

svy: tab party_id_alt_long if round==0
svy: tab party_id_alt_long if round==1
svy: tab race if round==0
svy: tab race if round==1
svy: mean college if round==0
svy: mean college if round==1
svy: mean male if round==0
svy: mean male if round==1
svy: mean income if round==0
svy: mean income if round==1
svy: mean age if round==0
svy: mean age if round==1
svy: mean county_density if round==0
svy: mean county_density if round==1
svy: mean dem_gov if round==0
svy: mean dem_gov if round==1
svy: mean dem_leg if round==0
svy: mean dem_leg if round==1
svy: mean high_risk if round==0
svy: mean high_risk if round==1
svy: tab div if round==0
svy: tab div  if round==1














/*

//PART C: RANDOM EFFECT MODEL 
melogit            blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast individual_responsibility  perceived_safety || COUNTYNAME: || respondent_id: 
//outreg2 using part2b, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

*/














//PART D: ACCOUNTING FOR SN CONTEXT

//PART 1: BY STATE TYPES

//republican states
vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov     virus_forecast individual_responsibility perceived_safety  if dem_leg==0, cluster(COUNTYNAME  respondent_id)
//outreg2 using state_rep, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap   dem_leg   virus_forecast individual_responsibility perceived_safety if dem_gov==0, cluster(COUNTYNAME  respondent_id)
//outreg2 using state_rep, word dec(2) alpha(.01, .05)
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

//dem states
vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov     virus_forecast individual_responsibility perceived_safety  if dem_leg==1, cluster(COUNTYNAME  respondent_id)
//outreg2 using state_dem, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap   dem_leg   virus_forecast individual_responsibility perceived_safety if dem_gov==1, cluster(COUNTYNAME  respondent_id)
//outreg2 using state_dem, word dec(2) alpha(.01, .05)
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

//unified
vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap     virus_forecast individual_responsibility  perceived_safety if dem_leg==0 & united==1, cluster(COUNTYNAME  respondent_id)
//outreg2 using state_rep, word dec(2) alpha(.01, .05)
margins, dydx(round) at(party=(0(1)6)) saving(file1, replace)
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap    virus_forecast individual_responsibility perceived_safety  if dem_leg==0 & united==1, cluster(COUNTYNAME  respondent_id) 
//outreg2 using state_dem, word dec(2) alpha(.01, .05)
margins, dydx(round) at(party=(0(1)6)) saving(file2, replace)
margins, at(party=(0(1)6) round=(0 1))

//combomarginsplot file1 file2 

//PART 2: EXCLUDE LOCAL BLAME FROM DV
gen blame_att_short_stateonly=blame_att_short
replace blame_att_short_stateonly=. if blame_att==1 
vcemway logit      blame_att_short_stateonly i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility  perceived_safety , cluster(COUNTYNAME  respondent_id)
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))
















//PART E: QUALITY CHECK
//QUALITY CHECK

//QC1: DURATION MODELS
sum duration if round==0, d  //373 418
sum duration if round==1, d // 492 554
gen cut_5_per=.
gen cut_10_per=.
gen cut_25_per=.
replace cut_5_per=1 if round==0 & duration<373
replace cut_5_per=1 if round==1 & duration<492
replace cut_10_per=1 if round==0 & duration<418
replace cut_10_per=1 if round==1 & duration<554
replace cut_25_per=1 if round==0 & duration<542
replace cut_25_per=1 if round==1 & duration<682

vcemway logit      blame_att_short i.party_id_alt_long##c.round           i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility perceived_safety if cut_5_per==., cluster(COUNTYNAME  respondent_id)
//outreg2 using main, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round           i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility perceived_safety if cut_10_per==., cluster(COUNTYNAME  respondent_id)
//outreg2 using main, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round           i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility perceived_safety if cut_25_per==., cluster(COUNTYNAME  respondent_id)
//outreg2 using main, word dec(2) alpha(.01, .05) replace
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))

vcemway logit      blame_att_short i.party_id_alt_long##c.round           i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility perceived_safety duration, cluster(COUNTYNAME  respondent_id)
margins, dydx(round) at(party=(0(1)6)) 
margins, at(party=(0(1)6) round=(0 1))



//QC2: Attention Check
vcemway logit      blame_att_short i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg   virus_forecast individual_responsibility perceived_safety if test_ways==., cluster(COUNTYNAME  respondent_id)
margins, dydx(round) at(party=(0(1)6)) //good

















//PART F: ACCOUNTING FOR NO/NS
vce2way mlogit      blame_att_short_nons i.party_id_alt_long##c.round i.race college male income psindex nsindex trust_science_polmotives trust_science_betterment trust_science_community  financial_impact_personal mental_impact_personal  financial_impact_network mental_impact_network  infected_personal infected_network high_risk age county_density county_covid_cap_cases state_cases_cap dem_gov dem_leg  virus_forecast  individual_responsibility perceived_safety, cluster(COUNTYNAME  respondent_id)
margins, dydx(round) at(party=(0(1)6)) 
mplotoffset, yline(0) level(95) recast(scatter)
margins, at(party=(0(1)6) round=(0 1)) 
mplotoffset,  level(95) recast(scatter)










	
	
